package com.webank.webase.chain.mgr.repository.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import com.webank.webase.chain.mgr.contract.entity.ContractParam;
import com.webank.webase.chain.mgr.repository.bean.TbContract;
import com.webank.webase.chain.mgr.repository.bean.TbContractExample;
import java.util.Optional;
import org.apache.ibatis.annotations.DeleteProvider;

public interface TbContractMapper {

    //    String getSystemContractBin(@Param("groupId") Integer groupId, @Param("contractName") String contractName);
    @SelectProvider(type = TbContractSqlProvider.class, method = "getByParam")
    TbContract getByParam(ContractParam param);

    @Select({ "select ", TbContractSqlProvider.ALL_COLUMN_FIELDS, " from tb_contract ", "where chain_id = #{chainId} ", "and group_id= #{groupId} ", "and contract_name = #{name} ", "and contract_path = #{path}" })
    TbContract getContract(@Param("chainId") int chainId, @Param("groupId") int groupId, @Param("name") String name, @Param("path") String path);

    @SelectProvider(type = TbContractSqlProvider.class, method = "selectByParam")
    List<TbContract> selectByParam(ContractParam param);

    @SelectProvider(type = TbContractSqlProvider.class, method = "countByParam")
    int countByParam(ContractParam param);

    @Update({ "update tb_contract set contract_bin = #{contractBin}, " + "contract_address = #{contractAddress} " + "where group_id = #{groupId} and contract_name = #{contractName}" })
    int updateSystemContract(@Param("groupId") Integer groupId, @Param("contractName") String contractName, @Param("contractBin") String contractBin, @Param("contractAddress") String contractAddress);

    @Delete({ "delete from tb_contract where chain_id = #{chainId}" })
    int deleteByChainId(@Param("chainId") Integer chainId);

    @Delete({ "delete from tb_contract where chain_id = #{chainId} and group_id = #{groupId}" })
    int deleteByChainIdAndGroupId(@Param("chainId") Integer chainId, @Param("groupId") Integer groupId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbContractSqlProvider.class, method = "countByExample")
    long countByExample(TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbContractSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_contract", "where contract_id = #{contractId,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer contractId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_contract (contract_path, contract_name, ", "chain_id, group_id, ", "save_by_agency, contract_address, ", "deploy_time, contract_status, ", "contract_type, description, ", "create_time, modify_time, ", "contract_source, contract_abi, ", "contract_bin, bytecode_bin)", "values (#{contractPath,jdbcType=VARCHAR}, #{contractName,jdbcType=VARCHAR}, ", "#{chainId,jdbcType=INTEGER}, #{groupId,jdbcType=INTEGER}, ", "#{saveByAgency,jdbcType=INTEGER}, #{contractAddress,jdbcType=VARCHAR}, ", "#{deployTime,jdbcType=TIMESTAMP}, #{contractStatus,jdbcType=TINYINT}, ", "#{contractType,jdbcType=TINYINT}, #{description,jdbcType=VARCHAR}, ", "#{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP}, ", "#{contractSource,jdbcType=LONGVARCHAR}, #{contractAbi,jdbcType=LONGVARCHAR}, ", "#{contractBin,jdbcType=LONGVARCHAR}, #{bytecodeBin,jdbcType=LONGVARCHAR})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "contractId", before = false, resultType = Integer.class)
    int insert(TbContract record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbContractSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "contractId", before = false, resultType = Integer.class)
    int insertSelective(TbContract record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbContractSqlProvider.class, method = "selectByExampleWithBLOBs")
    @Results({ @Result(column = "contract_id", property = "contractId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "contract_path", property = "contractPath", jdbcType = JdbcType.VARCHAR), @Result(column = "contract_name", property = "contractName", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "group_id", property = "groupId", jdbcType = JdbcType.INTEGER), @Result(column = "save_by_agency", property = "saveByAgency", jdbcType = JdbcType.INTEGER), @Result(column = "contract_address", property = "contractAddress", jdbcType = JdbcType.VARCHAR), @Result(column = "deploy_time", property = "deployTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_status", property = "contractStatus", jdbcType = JdbcType.TINYINT), @Result(column = "contract_type", property = "contractType", jdbcType = JdbcType.TINYINT), @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_source", property = "contractSource", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_abi", property = "contractAbi", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_bin", property = "contractBin", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "bytecode_bin", property = "bytecodeBin", jdbcType = JdbcType.LONGVARCHAR) })
    List<TbContract> selectByExampleWithBLOBs(TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbContractSqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "contract_id", property = "contractId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "contract_path", property = "contractPath", jdbcType = JdbcType.VARCHAR), @Result(column = "contract_name", property = "contractName", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "group_id", property = "groupId", jdbcType = JdbcType.INTEGER), @Result(column = "save_by_agency", property = "saveByAgency", jdbcType = JdbcType.INTEGER), @Result(column = "contract_address", property = "contractAddress", jdbcType = JdbcType.VARCHAR), @Result(column = "deploy_time", property = "deployTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_status", property = "contractStatus", jdbcType = JdbcType.TINYINT), @Result(column = "contract_type", property = "contractType", jdbcType = JdbcType.TINYINT), @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP) })
    List<TbContract> selectByExample(TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Select({ "select", "contract_id, contract_path, contract_name, chain_id, group_id, save_by_agency, ", "contract_address, deploy_time, contract_status, contract_type, description, ", "create_time, modify_time, contract_source, contract_abi, contract_bin, bytecode_bin", "from tb_contract", "where contract_id = #{contractId,jdbcType=INTEGER}" })
    @Results({ @Result(column = "contract_id", property = "contractId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "contract_path", property = "contractPath", jdbcType = JdbcType.VARCHAR), @Result(column = "contract_name", property = "contractName", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "group_id", property = "groupId", jdbcType = JdbcType.INTEGER), @Result(column = "save_by_agency", property = "saveByAgency", jdbcType = JdbcType.INTEGER), @Result(column = "contract_address", property = "contractAddress", jdbcType = JdbcType.VARCHAR), @Result(column = "deploy_time", property = "deployTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_status", property = "contractStatus", jdbcType = JdbcType.TINYINT), @Result(column = "contract_type", property = "contractType", jdbcType = JdbcType.TINYINT), @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_source", property = "contractSource", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_abi", property = "contractAbi", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_bin", property = "contractBin", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "bytecode_bin", property = "bytecodeBin", jdbcType = JdbcType.LONGVARCHAR) })
    TbContract selectByPrimaryKey(Integer contractId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbContractSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbContract record, @Param("example") TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbContractSqlProvider.class, method = "updateByExampleWithBLOBs")
    int updateByExampleWithBLOBs(@Param("record") TbContract record, @Param("example") TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbContractSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbContract record, @Param("example") TbContractExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbContractSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbContract record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Update({ "update tb_contract", "set contract_path = #{contractPath,jdbcType=VARCHAR},", "contract_name = #{contractName,jdbcType=VARCHAR},", "chain_id = #{chainId,jdbcType=INTEGER},", "group_id = #{groupId,jdbcType=INTEGER},", "save_by_agency = #{saveByAgency,jdbcType=INTEGER},", "contract_address = #{contractAddress,jdbcType=VARCHAR},", "deploy_time = #{deployTime,jdbcType=TIMESTAMP},", "contract_status = #{contractStatus,jdbcType=TINYINT},", "contract_type = #{contractType,jdbcType=TINYINT},", "description = #{description,jdbcType=VARCHAR},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "modify_time = #{modifyTime,jdbcType=TIMESTAMP},", "contract_source = #{contractSource,jdbcType=LONGVARCHAR},", "contract_abi = #{contractAbi,jdbcType=LONGVARCHAR},", "contract_bin = #{contractBin,jdbcType=LONGVARCHAR},", "bytecode_bin = #{bytecodeBin,jdbcType=LONGVARCHAR}", "where contract_id = #{contractId,jdbcType=INTEGER}" })
    int updateByPrimaryKeyWithBLOBs(TbContract record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Update({ "update tb_contract", "set contract_path = #{contractPath,jdbcType=VARCHAR},", "contract_name = #{contractName,jdbcType=VARCHAR},", "chain_id = #{chainId,jdbcType=INTEGER},", "group_id = #{groupId,jdbcType=INTEGER},", "save_by_agency = #{saveByAgency,jdbcType=INTEGER},", "contract_address = #{contractAddress,jdbcType=VARCHAR},", "deploy_time = #{deployTime,jdbcType=TIMESTAMP},", "contract_status = #{contractStatus,jdbcType=TINYINT},", "contract_type = #{contractType,jdbcType=TINYINT},", "description = #{description,jdbcType=VARCHAR},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "modify_time = #{modifyTime,jdbcType=TIMESTAMP}", "where contract_id = #{contractId,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbContract record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "contractId", keyColumn = "contract_id")
    @Insert({ "<script>", "insert into tb_contract (contract_path, ", "contract_name, chain_id, ", "group_id, save_by_agency, ", "contract_address, deploy_time, ", "contract_status, contract_type, ", "description, create_time, ", "modify_time, contract_source, ", "contract_abi, contract_bin, ", "bytecode_bin)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.contractPath,jdbcType=VARCHAR}, ", "#{detail.contractName,jdbcType=VARCHAR}, #{detail.chainId,jdbcType=INTEGER}, ", "#{detail.groupId,jdbcType=INTEGER}, #{detail.saveByAgency,jdbcType=INTEGER}, ", "#{detail.contractAddress,jdbcType=VARCHAR}, #{detail.deployTime,jdbcType=TIMESTAMP}, ", "#{detail.contractStatus,jdbcType=TINYINT}, #{detail.contractType,jdbcType=TINYINT}, ", "#{detail.description,jdbcType=VARCHAR}, #{detail.createTime,jdbcType=TIMESTAMP}, ", "#{detail.modifyTime,jdbcType=TIMESTAMP}, #{detail.contractSource,jdbcType=LONGVARCHAR}, ", "#{detail.contractAbi,jdbcType=LONGVARCHAR}, #{detail.contractBin,jdbcType=LONGVARCHAR}, ", "#{detail.bytecodeBin,jdbcType=LONGVARCHAR})</foreach></script>" })
    int batchInsert(List<TbContract> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_contract
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbContractSqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "contract_id", property = "contractId", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "contract_path", property = "contractPath", jdbcType = JdbcType.VARCHAR), @Result(column = "contract_name", property = "contractName", jdbcType = JdbcType.VARCHAR), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "group_id", property = "groupId", jdbcType = JdbcType.INTEGER), @Result(column = "save_by_agency", property = "saveByAgency", jdbcType = JdbcType.INTEGER), @Result(column = "contract_address", property = "contractAddress", jdbcType = JdbcType.VARCHAR), @Result(column = "deploy_time", property = "deployTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_status", property = "contractStatus", jdbcType = JdbcType.TINYINT), @Result(column = "contract_type", property = "contractType", jdbcType = JdbcType.TINYINT), @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR), @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP), @Result(column = "contract_source", property = "contractSource", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_abi", property = "contractAbi", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "contract_bin", property = "contractBin", jdbcType = JdbcType.LONGVARCHAR), @Result(column = "bytecode_bin", property = "bytecodeBin", jdbcType = JdbcType.LONGVARCHAR) })
    Optional<TbContract> getOneByExample(TbContractExample example);
}
